{include file="public/layout" /}

<body class="bodystyle" style="overflow-x: hidden;padding: 0;min-width: 674px;background: #fff;">
<style type="text/css">
    .ncap-form-default dd.opt { width: 79%; }
    .select-express {border: 1px solid red !important; color: red !important;}
</style>
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page" style="width: 664px;margin: 0 auto;">
    <div class="flexigrid">
        <form class="form-horizontal" id="postForm" action="{:url('Shop/order_send_operating', ['_ajax'=>1])}" method="post">
            <input type="hidden" name="order_id" value="{$OrderData.order_id}">
            <input type="hidden" name="order_code" value="{$OrderData.order_code}">
            <input type="hidden" name="users_id" value="{$OrderData.users_id}">
            <input type="hidden" name="consignee" value="{$OrderData.consignee}">

            <input type="hidden" name="express_id" id="express_id">
            <input type="hidden" name="express_name" id="express_name">
            <input type="hidden" name="express_code" id="express_code">

            <div class="ncap-form-default">
                {eq name="$OrderData.prom_type" value="0"}
                    <dl class="row">
                        <dt class="tit"> <label>收货人</label> </dt> <dd class="opt"> {$OrderData.consignee} </dd>
                    </dl>
                    <dl class="row">
                        <dt class="tit"> <label>联系方式</label> </dt> <dd class="opt"> {$OrderData.mobile} </dd>
                    </dl>
                    <dl class="row">
                        <dt class="tit"> <label>收货地址</label> </dt>
                        <dd class="opt">
                            {$OrderData.country} {$OrderData.province} {$OrderData.city} {$OrderData.district} {$OrderData.address}
                        </dd>
                    </dl>

                    <dl class="row">
                        <dt class="tit"> <label>发货方式</label> </dt>
                        <dd class="opt" style="line-height: 30px;">
                            <label>
                                <input type="radio" name="prom_type" value="0" {eq name="$OrderData.prom_type" value="0"}checked="checked"{/eq}>录入物流单号
                            </label>
                            &nbsp;&nbsp;&nbsp;
                            <label>
                                <input type="radio" name="prom_type" value="1" {eq name="$OrderData.prom_type" value="1"}checked="checked"{/eq}>无需物流
                            </label>
                        </dd>
                    </dl>
                {else/}
                    <input type="hidden" name="prom_type" value="1">
                {/eq}

                <div class="{eq name='$OrderData.prom_type' value='1'}none{/eq}" id="ShippingInfo">
                    <dl class="row">
                        <dt class="tit"> <label><em>*</em>快递公司</label> </dt>
                        <dd class="opt">
                            <select id="select_express" style="width: 300px;" onchange="SelectExpress(this);">
                                <option value="0">请选择</option>
                                {volist name="$express" id="vo"}
                                <option value="{$vo.express_id}" code="{$vo.express_code}" name="{$vo.express_name}" {eq name="$vo.express_code" value="$OrderData.express_code"}selected{/eq}>{$vo.express_name}</option>
                                {/volist}
                            </select>
                            <div class="express-tag">
                                {volist name="$express" id="vo"}
                                {if condition='$i <= 4'}
                                <span class="span_all span_{$vo.express_id} {eq name='$vo.express_code' value='$OrderData.express_code'} select-express {/eq}" data-id="{$vo.express_id}" data-code="{$vo.express_code}" data-name="{$vo.express_name}" data-i="{$i}" onclick="SpanSelectExpress(this);">{$vo.express_name}</span>
                                {/if}
                                {/volist}
                            </div>
                        </dd>
                    </dl>
                    <dl class="row">
                        <dt class="tit"> <label>快递费用</label> </dt> <dd class="opt"> ￥{$OrderData.shipping_fee} </dd>
                    </dl>
                    <dl class="row">
                        <dt class="tit"> <label><em>*</em>快递单号</label> </dt>
                        <dd class="opt">
                            <input type="text" value="{$OrderData.express_order}" name="express_order" id="express_order" class="input-txt">
                        </dd>
                    </dl>
                </div>

                <div class="{if condition='$OrderData.prom_type == 0 && $OrderData.prom_type_virtual == false'}none{/if}" id="VirtualDelivery">
                    <dl class="row">
                        <dt class="tit"> <label>给买家回复</label> </dt>
                        <dd class="opt">          
                            <textarea rows="5" cols="60" name="virtual_delivery" style="height:60px;">{$OrderData.virtual_delivery}</textarea>
                        </dd>
                    </dl>
                </div>
            </div>

            <div class="ncap-form-default">
                <div class="bot" style="padding-bottom:0px;">
                    <a href="JavaScript:void(0);" onclick="checkForm();" class="ncap-btn-big ncap-btn-green" id="submitBtn">
                        {eq name="$OrderData['order_status']" value='1'}
                            确认发货
                        {/eq}
                        {eq name="$OrderData['order_status']" value='2'}
                            修改保存
                        {/eq}
                    </a>
                </div>
            </div>
        </form>
    </div>
</div>

<script type="text/javascript">

    $(document).ready(function(){
        // 表格行点击选中切换
        $('#flexigrid > table>tbody >tr').click(function(){
            $(this).toggleClass('trSelected');
        });

        // 发货方式
        $('input[name="prom_type"]').click(function() {
            var prom_type = $(this).val();
            if (1 == prom_type) {
                $('#ShippingInfo').hide();
                $('#VirtualDelivery').show();
            } else {
                $('#ShippingInfo').show();
                $('#VirtualDelivery').hide();
            }
        });
    });

    // 下拉框选择
    function SelectExpress(obj) {
        // 选中的对象
        var selectObj = $(obj).find("option:selected");

        // 赋值隐藏域
        $('#express_id').val($(selectObj).attr('value'));
        $('#express_name').val($(selectObj).attr('name'));
        $('#express_code').val($(selectObj).attr('code'));

        // span选中效果
        $('.span_all').removeClass('select-express');
        $('.span_' + $(selectObj).attr('value')).addClass('select-express');
    }

    // span选择
    function SpanSelectExpress(obj) {
        // 赋值隐藏域
        $('#express_id').val($(obj).data('id'));
        $('#express_name').val($(obj).data('name'));
        $('#express_code').val($(obj).data('code'));

        // 下拉框选中效果
        var obj_i = $(obj).data('i');
        obj_i++;
        $("#select_express option:nth-child("+obj_i+")").prop("selected", 'selected');

        // span选中效果
        $('.span_all').removeClass('select-express');
        $('.span_' + $(obj).data('id')).addClass('select-express');
    }

    // 物流公司选择框
    function Express() {
        var url = "{:url('Shop/order_express')}";
        //iframe窗
        layer.open({
            type: 2,
            title: '选择快递',
            shadeClose: false,
            maxmin: false, //开启最大化最小化按钮
            area: ['60%', '80%'],
            content: url
        });
    }

    // 选中地址，关闭物流公司弹框
    function express(obj, express_id){
        var express_name = $(obj).parent().find('#express_name_'+express_id).val();
        var express_code = $(obj).parent().find('#express_code_'+express_id).val();
        $('#express_id').val(express_id);
        $('#express_name').val(express_name);
        $('#express_name_new').html(express_name);
        $('#express_code').val(express_code);
        layer.closeAll();
    }

    // 表单提交
    function checkForm() {
        // if (0 == $('input[name="prom_type"]:checked').val() && $('#express_order').val() == '') {
        //     showErrorMsg('配送单号不能为空！');
        //     $('#express_order').focus();
        //     return false;
        // }

        var _parent = parent;
        layer.confirm('此操作不可恢复，确认发货？', {
            
            area: ['480px', '190px'],
            move: false,
            title: '提示',
            btnAlign:'r',
            closeBtn: 3,
            btn: ['确定', '取消'] ,//按钮
            success: function () {
                  $(".layui-layer-content").css('text-align', 'left');
              }
        },function(){
            layer_loading('正在处理');
            $.ajax({
                type: "POST",
                url: $('#postForm').attr('action'),
                data: $('#postForm').serialize(),
                dataType: 'json',
                success: function (res) {
                    if(res.code == 1){
                        if (!res.data.email && !res.data.mobile && !res.data.notice) {
                            layer.closeAll();
                            layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                                _parent.window.location.reload();
                            });
                        } else {
                            if (res.data.email) SendEmail(res.data.email);
                            if (res.data.mobile) SendMobile(res.data.mobile);
                            if (res.data.notice) SendNotice(res.data.notice);
                            layer.closeAll();
                            layer.msg('发货成功', {icon: 1, time: 1000}, function(){
                                _parent.window.location.reload();
                            });
                        }
                    } else {
                        layer.closeAll();
                        layer.alert(res.msg, {icon: 2, title: false, closeBtn: 0});
                        return false;
                    }
                },
                error:function(e){
                    layer.closeAll();
                    layer.alert(e.responseText, {icon: 2, title: false, closeBtn: 0});
                }
            });
        });
    }

    function SendEmail(result) {
        if (result) {
            $.ajax({
                url: result.url,
                data: result.data,
                type:'post',
                dataType:'json'
            });
        }
    }

    function SendMobile(result) {
        if (result) {
            $.ajax({
                url: result.url,
                data: result.data,
                type:'post',
                dataType:'json'
            });
        }
    }

    function SendNotice(result) {
        if (result) {
            $.ajax({
                url: result.url,
                data: result,
                type:'post',
                dataType:'json'
            });
        }
    }
</script> 
